﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
    <style>
        table tr td img {
            height: 25px;
            border-radius: 8%;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <form action="version/list" method="post" name="userForm" id="userForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <table style="width: 20%">
                        <tr>
                            <td style="vertical-align:top;">
                                <c:if test="${fn:contains(butSet, 'add')}">
                                    <a class="btn btn-small btn-success" onclick="add();">新增</a>
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>应用宝版本号</th>
                            <th>应用宝版本码</th>
                            <th>备注</th>
                            <th>发布状态</th>
                            <th>创建者</th>
                            <th>发布者</th>
                            <th>发布时间</th>
                            <th>创建时间</th>
                            <th>修改时间</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody id="contentTbody">
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty versions}">
                                <c:forEach items="${versions}" var="version">
                                    <tr style="text-align: center">
                                        <td>${version.yingyongbaoMarket.version}</td>
                                        <td>${version.yingyongbaoMarket.version_code}</td>
                                        <td>${version.remark}</td>
                                        <c:choose>
                                            <c:when test="${version.status == 1}">
                                                <td style="color: blue">已发布</td>
                                            </c:when>
                                            <c:otherwise>
                                                <td style="color: red">待发布</td>
                                            </c:otherwise>
                                        </c:choose>
                                        <td>${version.creater}</td>
                                        <td>${version.publisher}</td>
                                        <td>
                                            <fmt:formatDate value="${version.publishtime}"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${version.createtime}"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${version.modifytime}"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td style="width: 60px;">
                                            <div class='hidden-phone visible-desktop btn-group'>
                                                <c:if test="${version.status == 1 and fn:contains(butSet, 'check')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="show('${version.id }');">
                                                        查看
                                                    </a>
                                                </c:if>
                                                <c:if test="${version.status == 0 and fn:contains(butSet, 'edit')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="edit('${version.id }');">
                                                        编辑
                                                    </a>
                                                </c:if>
                                                <c:if test="${version.status == 0 and fn:contains(butSet, 'put')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="put('${version.id }', '${version.yingyongbaoMarket.version }');">
                                                        发布
                                                    </a>
                                                </c:if>
                                                <c:if test="${version.status == 1 and fn:contains(butSet, 'open')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="forceUpdate('${version.id }', '${version.forceUpdateStatus }', '${version.yingyongbaoMarket.version }');">
                                                        <c:choose>
                                                            <c:when test="${version.forceUpdateStatus == 1}">关闭强制更新</c:when>
                                                            <c:otherwise>打开强制更新</c:otherwise>
                                                        </c:choose>
                                                    </a>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'del')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="del('${version.id }', '${version.yingyongbaoMarket.version }');">
                                                        <i class='icon-trash'></i>
                                                    </a>
                                                </c:if>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="10" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(function () {
        top.hangge();
        //日期框
        $('.date-picker').datepicker({autoclose: true});
        //下拉框
        $(".chzn-select").chosen({disable_search: true});
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
    });

    //新增
    function add() {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "添加版本";
        diag.URL = '<%=basePath%>version/toAdd';
        diag.Width = 1200;
        diag.Height = 450;
        diag.CancelEvent = function () { //关闭事件

            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                if ('${page.currentPage}' == '0') {
                    top.jzts();
                    setTimeout("self.location=self.location", 100);
                } else {
                    nextPage(${page.currentPage});
                }
            }
            diag.close();
        };
        diag.show();
    }

    //修改
    function edit(id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "编辑版本";
        diag.URL = '<%=basePath%>version/toEdit?id=' + id;
        diag.Width = 1200;
        diag.Height = 450;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage(${page.currentPage});
            }
            diag.close();
        };
        diag.show();
    }

    function forceUpdate(id, status, title) {
        var msg = "";
        if (status == 0) {
            msg = "是否打开强制更新[" + title + "]？";
            status = 1;
        } else if (status == 1) {
            msg = "是否关闭强制更新[" + title + "]？";
            status = 0;
        }
        bootbox.confirm(msg, function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id, "status": status};
                var url = "<%=basePath%>version/forceUpdateStatus";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("操作成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

    function put(id, version) {
        bootbox.confirm("是否发布版本[" + version + "]？", function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id, "status": status};
                var url = "<%=basePath%>version/updateStatus";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("操作成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

    //查看
    function show(id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "查看版本";
        diag.URL = '<%=basePath%>version/show?id=' + id;
        diag.Width = 1200;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage(${page.currentPage});
            }
            diag.close();
        };
        diag.show();
    }

    //删除
    function del(id, version) {
        bootbox.confirm("是否删除[" + version + "]?", function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id};
                var url = "<%=basePath%>version/del";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("删除成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

</script>
</body>
</html>
